package com.azunitech.apm.bundles.shell.commands;

import java.io.PrintStream;
import java.util.Dictionary;
import java.util.Enumeration;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import com.azunitech.apm.bundles.shell.BasicCommand;

/*
 * Export Related service configuration detail information
 */
public class CommandCONF extends BasicCommand<BundleContext>
{
	private static final String CMD_KEY = "conf";
	private static final String CMD_DESC = "Print details about serving configuration";
	
	public String getKey() 
	{
		return CommandCONF.CMD_KEY;
	}

	public String getDesc() 
	{
		return CommandCONF.CMD_DESC;
	}

	public void exec(String args, PrintStream out, PrintStream err)
			throws Exception 
	{
		String id = args.substring(5);
		BundleContext context = this.m_target;
		Bundle bundle;
		if ( id == null || id.length() == 0)
		{
			 bundle = context.getBundle();
		}
		else
		{
			bundle = context.getBundle(Long.parseLong(id));
		}
		Dictionary<String, String> headers = bundle.getHeaders();
		Enumeration<String> keys = headers.keys(); 
		while (keys.hasMoreElements())
		{
			String key = keys.nextElement();
			String val = headers.get(key);
			
			out.println(key + ":" + val);
			out.println("\r");
		}
		
		out.println("LastModified:" + bundle.getLastModified());
		out.println("\r");
		out.println("SymbolicName:" + bundle.getSymbolicName());
		out.println("\r");
		out.println("Loction:" + bundle.getLocation());
		out.println("\r");
	}
}
